<template>
  <div class="picture-ai-painting">
    <div class="tabs-container" :class="{ 'tabs-hidden': !showTabs }">
      <a-tabs v-model:activeKey="activeKey" tab-position="left" class="custom-tabs">
        <a-tab-pane key="1" tab="暂无" disabled> 1111</a-tab-pane>
        <a-tab-pane key="2" tab="查询扩图任务">
          <div class="task-list-container">
            <!-- 最新扩展任务大图展示 -->
            <div v-if="pictureList.length > 0" class="latest-task">
              <h3 class="section-subtitle">最新扩展任务</h3>
              <a-card hoverable class="latest-task-card">
                <a-row :gutter="16">
                  <a-col :span="12">
                    <div class="latest-image-wrapper">
                      <a-image
                        :src="pictureList[0].originalPictureUrl"
                        class="latest-task-image"
                        alt="原始图片"
                      />
                      <div class="image-label">原始图片</div>
                    </div>
                  </a-col>
                  <a-col :span="12">
                    <div class="latest-image-wrapper">
                      <a-image
                        v-if="pictureList[0].expandedPictureUrl"
                        :src="pictureList[0].expandedPictureUrl"
                        class="latest-task-image"
                        alt="扩展后图片"
                      />
                      <div v-else class="task-status latest-task-status">
                        <div class="loading-container" v-if="pictureList[0].status === 0">
                          <a-progress :percent="loadingProgress" status="active" />
                          <div class="loading-tip">
                            <p>图片扩展中，预计需要一段时间</p>
                            <p class="tip-small">您可以先去做其他事情，稍后再回来查看结果</p>
                            <a-button type="link" size="small" @click="cancelLoading"
                              >取消等待</a-button
                            >
                          </div>
                        </div>
                        <a-tag v-else :color="getStatusColor(pictureList[0].status)">
                          {{ getStatusText(pictureList[0].status) }}
                        </a-tag>
                      </div>
                      <div class="image-label">扩展后图片</div>
                    </div>
                  </a-col>
                </a-row>
                <template #actions>
                  <a-space>
                    <a-button
                      v-if="pictureList[0].expandedPictureUrl"
                      type="primary"
                      @click="
                        goDownLoadImage(
                          pictureList[0].expandedPictureUrl,
                          `expanded_${pictureList[0].taskId}`,
                        )
                      "
                    >
                      <template #icon>
                        <DownloadOutlined />
                      </template>
                      下载
                    </a-button>
                    <a-tooltip v-if="pictureList[0].expandedPictureUrl">
                      <template #title>上传到私人空间</template>
                      <a-button
                        type="primary"
                        ghost
                        @click="
                          addPictureToMySpace(
                            pictureList[0].expandedPictureUrl,
                            `expanded_${pictureList[0].taskId}`,
                          )
                        "
                      >
                        <template #icon>
                          <UploadOutlined />
                        </template>
                        保存
                      </a-button>
                    </a-tooltip>
                  </a-space>
                </template>
              </a-card>
            </div>

            <!-- 历史任务列表 -->
            <div class="history-tasks">
              <div class="history-header">
                <h3 class="section-subtitle">历史任务</h3>
                <a-button type="link" @click="toggleHistoryList">
                  <template #icon>
                    <DownOutlined v-if="showHistoryList" />
                    <RightOutlined v-else />
                  </template>
                  {{ showHistoryList ? '收起' : '展开' }}
                </a-button>
              </div>

              <div v-show="showHistoryList" class="history-list">
                <a-list
                  :data-source="pictureList.slice(1)"
                  :loading="loading"
                  :pagination="pagination"
                  :grid="{ gutter: 24, xs: 1, sm: 1, md: 2, lg: 2, xl: 3, xxl: 3 }"
                >
                  <template #renderItem="{ item }">
                    <a-list-item>
                      <a-card hoverable class="history-task-card">
                        <div class="history-image-container">
                          <!-- 左右布局 -->
                          <div class="history-image-row">
                            <!-- 原始图片 -->
                            <div class="history-image-wrapper">
                              <a-image
                                :src="item.originalPictureUrl"
                                class="history-task-image"
                                alt="原始图片"
                              />
                              <div class="image-label">原始图片</div>
                            </div>
                            <!-- 扩展图片 -->
                            <div class="history-image-wrapper">
                              <template v-if="item.expandedPictureUrl">
                                <a-image
                                  :src="item.expandedPictureUrl"
                                  class="history-task-image"
                                  alt="扩展后图片"
                                />
                              </template>
                              <div v-else class="task-status">
                                <div class="loading-container-small" v-if="item.status === 0">
                                  <a-progress
                                    :percent="loadingProgress"
                                    size="small"
                                    status="active"
                                  />
                                  <div class="loading-tip-small">处理中...</div>
                                </div>
                                <a-tag v-else :color="getStatusColor(item.status)">
                                  {{ getStatusText(item.status) }}
                                </a-tag>
                              </div>
                              <div class="image-label">扩展后图片</div>
                            </div>
                          </div>
                        </div>
                        <template #actions>
                          <a-space>
                            <a-button
                              v-if="item.expandedPictureUrl"
                              type="link"
                              size="small"
                              @click="
                                goDownLoadImage(item.expandedPictureUrl, `expanded_${item.taskId}`)
                              "
                            >
                              <DownloadOutlined />
                              <span>下载</span>
                            </a-button>
                            <a-button
                              v-if="item.expandedPictureUrl"
                              type="link"
                              size="small"
                              @click="
                                addPictureToMySpace(
                                  item.expandedPictureUrl,
                                  `expanded_${item.taskId}`,
                                )
                              "
                            >
                              <UploadOutlined />
                              <span>保存</span>
                            </a-button>
                          </a-space>
                        </template>
                      </a-card>
                    </a-list-item>
                  </template>
                </a-list>
              </div>
            </div>
          </div>
        </a-tab-pane>

        <a-tab-pane key="3" tab="创建扩图任务">
          <div class="task-create-container">
            <h2 class="section-title">AI 图像扩展</h2>
            <p class="section-desc">上传图片，让 AI 为您扩展图像尺寸和内容</p>

            <a-card class="upload-card">
              <a-row :gutter="16" justify="center">
                <a-col :span="24">
                  <a-upload
                    v-model:file-list="fileList"
                    name="avatar"
                    list-type="picture-card"
                    :show-upload-list="false"
                    :before-upload="beforeUpload"
                    :custom-request="getFileUrl"
                    class="upload-area"
                  >
                    <div class="upload-content">
                      <a-space direction="vertical" align="center">
                        <div class="preview-container">
                          <a-image
                            :src="fileUrl"
                            :preview="false"
                            v-if="fileUrl"
                            class="preview-image"
                          />
                          <div v-else class="upload-placeholder">
                            <CloudUploadOutlined class="upload-icon" />
                            <div class="upload-text">点击上传图片</div>
                            <div class="upload-hint">支持 jpg/png 格式，大小不超过 2MB</div>
                          </div>
                        </div>
                      </a-space>
                    </div>
                  </a-upload>
                </a-col>

                <a-col :span="24" class="action-area">
                  <a-button
                    :disabled="!fileUrl"
                    type="primary"
                    @click="doPaintingImage"
                    :loading="!!taskId"
                    block
                    size="large"
                    class="expand-btn"
                  >
                    <template #icon><RedditOutlined /></template>
                    开始扩展图像 (剩余次数：{{ userStore?.userInfo?.expandCount || 0 }})
                  </a-button>
                </a-col>
              </a-row>
            </a-card>
          </div>
        </a-tab-pane>
      </a-tabs>
    </div>

    <a-button class="toggle-tabs-btn" type="primary" shape="circle" @click="toggleTabs">
      <template #icon>
        <MenuFoldOutlined v-if="showTabs" />
        <MenuUnfoldOutlined v-else />
      </template>
    </a-button>

    <ShareModal v-model="open" title="分享图片" :share-url="shareUrl" />
  </div>
</template>

<script lang="ts" setup>
import {
  aiCreateImageOutPaintingUsingPost,
  getPictureOutPaintingListUsingPost,
} from '@/api/aiChatController.ts'
import { uploadFileUsingPost } from '@/api/fileController.ts'
import ShareModal from '@/components/ShareModal.vue'
import { useUserStore } from '@/stores/user.ts'
import { downloadImage } from '@/utils'
import { doAddPicture } from '@/utils/picture.ts'
import {
  CloudUploadOutlined,
  DownloadOutlined,
  MenuFoldOutlined,
  MenuUnfoldOutlined,
  RedditOutlined,
  UploadOutlined,
  DownOutlined,
  RightOutlined,
} from '@ant-design/icons-vue'
import { message } from 'ant-design-vue'
import { onMounted, onUnmounted, ref } from 'vue'
import { useRouter } from 'vue-router'

const fileList = ref([])
const loading = ref<boolean>(false)
const activeKey = ref('3')
const userStore = useUserStore()
const router = useRouter()

interface UploadFileInfo {
  file: File
}

const fileUrl = ref<string>('')
const getFileUrl = async ({ file }: UploadFileInfo) => {
  loading.value = true
  try {
    const res = await uploadFileUsingPost({}, file)
    if (res.data?.code === 0 && res.data?.data) {
      fileUrl.value = res.data.data
    }
  } catch (error: unknown) {
    if (error instanceof Error) {
      console.log(error.message)
    } else {
      console.log('上传失败')
    }
  }
  loading.value = false
}

const beforeUpload = (file: File) => {
  const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png'
  if (!isJpgOrPng) {
    message.error('只能上传格式为jpeg，和png')
  }
  const isLt2M = file.size / 1024 / 1024 < 2
  if (!isLt2M) {
    message.error('图片大小不超过2MB')
  }
  return isJpgOrPng && isLt2M
}

// 扩展图片
const taskId = ref<string>('')
const paintingLoading = ref<boolean>(false)
const paintingImgUrl = ref<string>('')

const doPaintingImage = async () => {
  paintingLoading.value = true
  try {
    const res = await aiCreateImageOutPaintingUsingPost({
      fileUrl: fileUrl.value,
      parameters: {
        xScale: 2,
        yScale: 2,
      },
    })
    if (res.data.code === 0 && res.data.data?.output?.task_id) {
      message.success('任务创建成功，请不要退出，耐心等待')
      taskId.value = res.data.data.output.task_id
      activeKey.value = '2'
      startPolling()
    }
  } catch (error: unknown) {
    if (error instanceof Error) {
      message.error(`创建任务失败: ${error.message}`)
    } else {
      message.error('创建任务失败')
    }
    paintingLoading.value = false
  }
}

// 添加加载进度相关变量
const loadingProgress = ref<number>(0)
const progressInterval = ref<number | null>(null)

const clearPolling = () => {
  if (progressInterval.value) {
    clearInterval(progressInterval.value)
    progressInterval.value = null
  }
  taskId.value = ''
}

const resetUploadState = () => {
  fileUrl.value = ''
  fileList.value = []
}

// 修改轮询逻辑，改为获取图片列表
const startPolling = () => {
  if (!taskId.value) {
    return
  }

  // 立即执行一次获取列表
  getPictureList()

  // 启动进度条
  startProgressAnimation()

  const pollInterval = setInterval(async () => {
    try {
      // 获取图片列表
      await getPictureList()

      // 检查当前任务是否完成
      const currentTask = pictureList.value.find((item) => item.taskId === taskId.value)
      if (currentTask) {
        if (currentTask.status === 1) {
          // 任务完成
          clearInterval(pollInterval)
          clearPolling()
          resetUploadState()
          message.success('图片扩展完成')
          // 更新用户信息
          userStore.fetchUserInfo()
        } else if (currentTask.status === 2) {
          // 任务失败
          clearInterval(pollInterval)
          clearPolling()
          resetUploadState()
          message.error(currentTask.errorMessage || '图片扩展失败')
        }
      }
    } catch (error: unknown) {
      if (error instanceof Error) {
        console.log(error.message)
      }
      clearInterval(pollInterval)
      clearPolling()
      resetUploadState()
    }
  }, 10000) // 每10秒轮询一次
}

// 添加进度条动画
const startProgressAnimation = () => {
  loadingProgress.value = 0

  // 清除可能存在的旧定时器
  if (progressInterval.value) {
    clearInterval(progressInterval.value)
  }

  // 创建新的进度条动画
  progressInterval.value = setInterval(() => {
    if (loadingProgress.value < 99) {
      // 前期快速增长，后期缓慢
      if (loadingProgress.value < 50) {
        loadingProgress.value += 5
      } else if (loadingProgress.value < 80) {
        loadingProgress.value += 2
      } else if (loadingProgress.value < 95) {
        loadingProgress.value += 0.5
      } else {
        loadingProgress.value += 0.1
      }
    }
  }, 500) // 每0.5秒更新一次
}

// 取消加载
const cancelLoading = () => {
  clearPolling()
  resetUploadState()
  activeKey.value = '3' // 切换回创建任务标签页
  message.info('已取消等待，您可以稍后再查看结果')
}

// 获取扩展图片列表
const pictureList = ref<API.ImageExpansion[]>([])
const pagination = ref({
  current: 1,
  pageSize: 10,
  total: 0,
  onChange: (page: number, pageSize: number) => {
    pagination.value.current = page
    pagination.value.pageSize = pageSize
    getPictureList()
  },
})

const getPictureList = async () => {
  loading.value = true
  try {
    const res = await getPictureOutPaintingListUsingPost({
      current: pagination.value.current,
      pageSize: pagination.value.pageSize,
    })
    if (res.data.code === 0 && res.data.data) {
      pictureList.value = res.data.data.records || []
      pagination.value.total = res.data.data.total || 0

      // 如果有正在进行的任务，更新其状态
      if (taskId.value) {
        const currentTask = pictureList.value.find((item) => item.taskId === taskId.value)
        if (currentTask?.expandedPictureUrl) {
          paintingImgUrl.value = currentTask.expandedPictureUrl
        }
      }
    }
  } catch (error: unknown) {
    if (error instanceof Error) {
      console.error('获取扩图任务列表失败:', error.message)
    } else {
      console.error('获取扩图任务列表失败:', '未知错误')
    }
  } finally {
    loading.value = false
  }
}

// 上传url图片
// 分享操作
const open = ref<boolean>(false)
const shareUrl = ref<string>('')

// 下载图片
const goDownLoadImage = (url: string, fileName: string) => {
  downloadImage(url, fileName)
}

// 上传图片
const addPictureToMySpace = async (url: string, name: string) => {
  await doAddPicture(url, name)
  await router.push({
    path: '/space/my',
  })
}

// 添加标签栏显示控制
const showTabs = ref(true)
const toggleTabs = () => {
  showTabs.value = !showTabs.value
  getPictureList()
}

// 获取任务状态颜色
const getStatusColor = (status?: number) => {
  switch (status) {
    case 0:
      return 'processing'
    case 1:
      return 'success'
    case 2:
      return 'error'
    default:
      return 'default'
  }
}

// 获取任务状态文本
const getStatusText = (status?: number) => {
  switch (status) {
    case 0:
      return '处理中'
    case 1:
      return '已完成'
    case 2:
      return '失败'
    default:
      return '未知'
  }
}

// 添加新的响应式变量
const showHistoryList = ref(true)

// 添加新的方法
const toggleHistoryList = () => {
  showHistoryList.value = !showHistoryList.value
}

onMounted(() => {
  getPictureList()
})
onUnmounted(() => {
  clearPolling()
})
</script>

<style scoped lang="scss">
.picture-ai-painting {
  padding: 24px;
  min-height: calc(100vh - 48px);
  background-color: #f0f2f5;
  display: flex;
  flex-direction: column;
  position: relative;
}

.section-title {
  font-size: 24px;
  font-weight: 600;
  color: #1a1a1a;
  margin-bottom: 8px;
  text-align: center;
}

.section-desc {
  font-size: 14px;
  color: #666;
  text-align: center;
  margin-bottom: 24px;
}

.tabs-container {
  flex: 1;
  background: white;
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  transition: all 0.3s ease;

  &.tabs-hidden {
    :deep(.ant-tabs-nav) {
      transform: translateX(-100%);
      width: 0;
      opacity: 0;
    }
  }
}

.custom-tabs {
  height: 100%;

  :deep(.ant-tabs-nav) {
    background: #fafafa;
    padding: 16px 0;
    width: 200px;
    border-right: 1px solid #f0f0f0;
    transition: all 0.3s;

    .ant-tabs-tab {
      margin: 0 !important;
      padding: 16px 24px !important;
      transition: all 0.3s;

      &:hover {
        background: #e6f7ff;
      }

      &.ant-tabs-tab-active {
        background: #e6f7ff;
        color: #1890ff;
      }
    }
  }

  :deep(.ant-tabs-content) {
    padding: 24px;
  }
}

.task-create-container,
.task-result-container {
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.upload-card {
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);

  .upload-area {
    width: 100%;

    :deep(.ant-upload) {
      width: 100%;
      height: 360px;
      border-radius: 8px;
      border: 2px dashed #d9d9d9;
      background: #fafafa;
      transition: all 0.3s;

      &:hover {
        border-color: #1890ff;
        background: #e6f7ff;
      }
    }
  }
}

.upload-content {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-container {
  width: 100%;
  height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;

  :deep(.ant-image) {
    width: 100%;
    height: 100%;

    .ant-image-img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }
}

.upload-placeholder {
  text-align: center;

  .upload-icon {
    font-size: 48px;
    color: #1890ff;
    margin-bottom: 16px;
  }

  .upload-text {
    font-size: 16px;
    color: #666;
    margin-bottom: 8px;
  }

  .upload-hint {
    font-size: 12px;
    color: #999;
  }
}

.preview-image {
  max-width: 100%;
  max-height: 340px;
  object-fit: contain;
}

.action-area {
  margin-top: 24px;

  .expand-btn {
    height: 48px;
    font-size: 16px;
    border-radius: 8px;
  }
}

.result-content {
  .image-preview {
    background: white;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 24px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);

    .result-image {
      width: 100%;
      max-height: 500px;
      object-fit: contain;
    }
  }

  .result-actions {
    .filename-input {
      margin-bottom: 16px;
    }

    .action-buttons {
      display: flex;
      justify-content: center;
      gap: 16px;

      :deep(.ant-btn) {
        height: 40px;
        padding: 0 24px;

        .anticon {
          font-size: 16px;
        }
      }
    }
  }
}

.toggle-tabs-btn {
  position: fixed;
  top: 24px;
  left: 24px;
  width: 40px;
  height: 40px;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);

  &:hover {
    transform: scale(1.1);
  }
}

// 响应式设计
@media (max-width: 768px) {
  .picture-ai-painting {
    padding: 16px;
  }

  .section-title {
    font-size: 20px;
  }

  .upload-card {
    :deep(.ant-upload) {
      height: 280px !important;
    }
  }

  .action-buttons {
    flex-direction: column;

    :deep(.ant-btn) {
      width: 100%;
    }
  }

  .toggle-tabs-btn {
    top: 16px;
    left: 16px;
  }
}

.result-image-container {
  width: 100%;
  max-width: 600px;
  height: 400px;
  margin: 0 auto;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  background-color: #f5f5f5;

  :deep(.ant-image) {
    width: 100%;
    height: 100%;

    .ant-image-img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }
}

.filename-input {
  max-width: 400px;
  margin: 20px auto;
  display: block;
}

.task-list-container {
  margin-top: 24px;
  padding: 0 24px;
}

.section-subtitle {
  font-size: 18px;
  font-weight: 500;
  color: #1a1a1a;
  margin-bottom: 16px;
}

.latest-task {
  margin-bottom: 32px;

  .latest-task-card {
    border-radius: 12px;
    transition: all 0.3s ease;

    &:hover {
      transform: translateY(-4px);
      box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    }
  }
}

.latest-image-wrapper {
  position: relative;
  width: 100%;
  height: 400px;
  border-radius: 8px;
  overflow: hidden;
  background-color: #f5f5f5;
}

.latest-task-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.latest-task-status {
  height: 400px;
  display: flex;
  align-items: center;
  justify-content: center;

  .loading-container {
    width: 80%;
    text-align: center;

    .ant-progress {
      margin-bottom: 16px;
    }

    .loading-tip {
      color: #666;

      p {
        margin: 8px 0;
        font-size: 14px;
      }

      .tip-small {
        font-size: 12px;
        color: #999;
      }
    }
  }
}

.task-status {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  width: 80%;

  .loading-container-small {
    .ant-progress {
      margin-bottom: 8px;
    }

    .loading-tip-small {
      font-size: 12px;
      color: #666;
    }
  }

  .ant-tag {
    font-size: 14px;
    padding: 4px 12px;
  }
}

.history-tasks {
  margin-top: 32px;

  .history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding: 0 12px;
  }

  .history-list {
    transition: all 0.3s ease;
    padding: 0 12px;

    :deep(.ant-list) {
      margin: 0 -12px;
    }

    :deep(.ant-list-item) {
      padding: 12px;
    }
  }
}

.history-task-card {
  border-radius: 12px;
  overflow: hidden;
  transition: all 0.3s ease;
  background: #fff;
  border: 1px solid #f0f0f0;
  height: 100%;

  &:hover {
    transform: translateY(-4px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
    border-color: transparent;
  }

  .history-image-container {
    padding: 12px;
    aspect-ratio: 16/9;
    display: flex;
    align-items: center;
  }

  .history-image-row {
    display: flex;
    gap: 12px;
    width: 100%;
    height: 100%;
  }

  .history-image-wrapper {
    position: relative;
    width: 50%;
    height: 100%;
    background-color: #f5f5f5;
    border-radius: 8px;
    overflow: hidden;

    .ant-image {
      width: 100%;
      height: 100%;

      img {
        width: 100%;
        height: 100%;
        object-fit: contain;
      }
    }

    .image-label {
      position: absolute;
      bottom: 0;
      left: 0;
      right: 0;
      padding: 6px;
      background: rgba(0, 0, 0, 0.6);
      color: white;
      font-size: 12px;
      text-align: center;
      backdrop-filter: blur(4px);
    }

    .task-status {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      text-align: center;
      width: 80%;
      background: rgba(255, 255, 255, 0.9);
      padding: 12px;
      border-radius: 8px;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);

      .loading-container-small {
        .ant-progress {
          margin-bottom: 8px;
        }

        .loading-tip-small {
          font-size: 12px;
          color: #666;
        }
      }

      .ant-tag {
        font-size: 14px;
        padding: 4px 12px;
      }
    }
  }

  :deep(.ant-card-actions) {
    background: #fafafa;
    border-top: 1px solid #f0f0f0;

    li {
      margin: 4px 0;
    }

    .ant-btn {
      padding: 4px 8px;
      height: auto;

      .anticon {
        font-size: 16px;
        margin-right: 4px;
      }

      span {
        font-size: 12px;
      }

      &:hover {
        color: #1890ff;
        background: #e6f7ff;
      }
    }
  }
}

// 响应式设计
@media (max-width: 768px) {
  .history-tasks {
    margin-top: 24px;

    .history-list {
      padding: 0 8px;

      :deep(.ant-list) {
        margin: 0 -8px;
      }

      :deep(.ant-list-item) {
        padding: 8px;
      }
    }
  }

  .history-task-card {
    .history-image-container {
      padding: 8px;
    }

    .history-image-row {
      gap: 8px;
    }
  }
}

// 平板设备优化
@media screen and (min-width: 769px) and (max-width: 1024px) {
  .history-task-card {
    .history-image-container {
      aspect-ratio: 4/3;
    }
  }
}

// 大屏幕优化
@media screen and (min-width: 1025px) {
  .history-task-card {
    .history-image-container {
      aspect-ratio: 16/9;
    }
  }
}
</style>
